package User

import (
	"net/http"

	M "ICan/MySql"
	"ICan/errmsg"
	_ "github.com/go-sql-driver/mysql"
	"github.com/gin-gonic/gin"
)
type history struct {
	Animation_id string `json:"animation_id"`
 	Num int `json:"num"`
	Time string `json:"time"`
}
func FHistory(ctx *gin.Context){
	user_id := ctx.PostForm("user_id")
	sqlstr := `select bro_animation_id, bro_num, bro_time from history where bro_user_id = ?`
	rows, _ := M.Db.Query(sqlstr, user_id)
	defer rows.Close()
	var his = make([]history, 0)
	for rows.Next() {
		var u history
		rows.Scan(&u.Animation_id, &u.Num, &u.Time)
		his = append(his, history{
			Animation_id:u.Animation_id,
			Num:u.Num,
			Time:u.Time,
		})
	}
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
		"data":his,
	}
	ctx.JSON(http.StatusOK, data)
}
